import 'package:flutter/material.dart';

import 'public_app_bar.dart';

/// FileName web_app_bar
///
/// @Author lax
/// @Date 2024/4/2
///
/// @Description

class WebAppBar extends PublicAppBar {
  final bool isShowClose;

  final VoidCallback? onGoBack;

  final VoidCallback? onClose;

  WebAppBar({
    super.key,
    super.isShowLeading,
    super.title,
    super.titleStyle,
    super.titleWidget,
    super.actions,
    super.toolHeight,
    super.backWidget,
    super.frontWidget,
    super.statusBarBrightness,
    super.color,
    super.decoration,
    super.appBarBuilder,
    this.isShowClose = false,
    this.onGoBack,
    this.onClose,
  }) : super(
          leading: leadingWidget(
              color: titleStyle?.color,
              isShowClose: isShowClose,
              onGoBack: onGoBack,
              onClose: onClose),
          leadingWidth:
              isShowClose ? (12 * 2 + 20 * 2 + 8 * 2) : (12 * 2 + 20),
        );

  static Widget leadingWidget({
    Color? color,
    bool isShowClose = false,
    VoidCallback? onGoBack,
    VoidCallback? onClose,
  }) {
    return Builder(builder: (context) {
      return Row(
        children: [
          GestureDetector(
            child: Container(
              color: Colors.transparent,
              height: double.infinity,
              padding: EdgeInsets.only(
                  left: 12, right: isShowClose ? 8 : 12),
              child: Icon(
                Icons.arrow_back_ios_new,
                color: color ?? Colors.white,
                size: 20,
              ),
            ),
            onTap: () {
              if (onGoBack != null) {
                onGoBack();
              } else {
                Navigator.pop(context);
              }
            },
          ),
          Visibility(
            visible: isShowClose,
            child: GestureDetector(
              child: Container(
                color: Colors.transparent,
                height: double.infinity,
                padding: const EdgeInsets.only(left: 8, right: 12),
                child: Icon(
                  Icons.close,
                  color: color ?? Colors.white,
                  size: 20,
                ),
              ),
              onTap: () {
                if (onClose != null) {
                  onClose();
                } else {
                  Navigator.pop(context);
                }
              },
            ),
          ),
        ],
      );
    });
  }
}
